package top.ashman.demo.springcloud.hystrix.command;

import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.HystrixCommandGroupKey;
import top.ashman.demo.springcloud.hystrix.MyUtil;

/**
 * 用于以 Hystrix 的方式执行请求
 *
 * @author sunzhaojie
 * @date 2018-12-10
 * @see MySleepCommand
 * @see MySleepCommandWithFallback
 */
public class MySleepCommandWithFallback extends HystrixCommand<String> {

    MySleepCommandWithFallback() {
        super(HystrixCommandGroupKey.Factory.asKey("myGroup"));
    }

    @Override
    protected String run() throws Exception {
        var response = MyUtil.request("http://localhost:8765/my/sleep/3000");
        MyUtil.printResponse(response);
        return response.body();
    }

    @Override
    protected String getFallback() {
        return "fallback";
    }
}
